<?php defined('LFNC_VERSION') or die('forbidden');


/**
* MLT Web Engine
* http://www.molotsoft.ru
*
* @package MLT_WE
* @subpackage Lucky_Funcs
* @author Ivan Chistyakov <ivan@molotsoft.ru>
* @version $Id: mail.lfnc.php 172 2009-03-11 06:05:16Z molotsoft@gmail.com $
* @link $HeadURL: http://lucky-funcs.googlecode.com/svn/branches/version_1/funcs/mail.lfnc.php $
*/


function mime_word_encode($word, $charset = 'utf-8') {
	return '=?' . $charset . '?B?' . base64_encode($word) . '?=';
}

function simple_mail($from, $to, $subject, $message, $content_type = 'text/plain', $charset = 'utf-8') {
	$headers = 'MIME-Version: 1.0' . CRLF;
	$headers .= 'Content-Type: ' . $content_type . '; charset=' . $charset . CRLF;
	$headers .= 'From: ' . $from . CRLF;
	$headers .= 'To: ' . $to . CRLF;
	return mail($to, mime_word_encode($subject, $charset), trim($message), $headers);
}

function simple_mail_attachment($from, $to, $subject, $message, $filename, $data, $content_type = 'text/plain', $charset = 'utf-8') {
	$boundary = '----------' . strtoupper(uniqid(time()));
	$headers = 'MIME-Version: 1.0' . CRLF;
	$headers .= 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . CRLF;
	$headers .= 'From: ' . $from . CRLF;
	$headers .= 'To: ' . $to . CRLF;
	$parts = '--' . $boundary . CRLF;
	$parts .= 'Content-Transfer-Encoding: 8bit' . CRLF;
	$parts .= 'Content-Type: ' . $content_type . '; charset=' . $charset . CRLF;
	$parts .= CRLF;
	$parts .= trim($message) . CRLF;
	$parts .= '--' . $boundary . CRLF;
	$parts .= 'Content-Transfer-Encoding: base64' . CRLF;
	$parts .= 'Content-Disposition: attachment; filename="' . mime_word_encode($filename) . '"' . CRLF;
	$parts .= 'Content-Type: application/octet-stream; name="' . mime_word_encode($filename) . '"' . CRLF;
	$parts .= CRLF;
	$parts .= trim(chunk_split(base64_encode($data))) . CRLF;
	$parts .= '--' . $boundary . '--';
	return mail($to, mime_word_encode($subject, $charset), $parts, $headers);
}


?>